<template>
  <div class="search-box">
    <i class="icon-search icon-font">&#xe6ac;</i>
    <input ref="query" v-model="query" class="box" :placeholder="placeholder"/>
    <i @click="clear" v-show="query" class="icon-dismiss icon-font"> &#xe69a;</i>

  </div>
</template>

<script>
  import {debounce} from 'common/js/util'

  export default {
    props: {
      placeholder: {
        type: String,
        default: '搜索商品，请输入关键词'
      }
    },
    data() {
      return {
        query: ''
      }
    },
    methods: {
      clear() {
        this.query = ''
      },
      setQuery(query) {
        this.query = query
      },
      blur() {
        this.$refs.query.blur()
      }
    },
    created() {
      this.$watch('query', debounce((newQuery) => {
        this.$emit('query', newQuery)
      }, 200))
    }
  }
</script>

<style scoped lang="scss" rel="stylesheet/css">
  @import "~common/scss/variable";
  @import "~common/scss/mixin";
  .search-box{
    display: flex;
    align-items: center;
    box-sizing: border-box;
    width: 80%;
    height: 30px;
    line-height: 30px;
    margin-left:45px;
    background: $color-background;
    border-radius: 6px;
    .icon-search{
      font-size: 14px;
          margin: 0 4px;
      color: $color-text-ll;  
    }
    .box{
      flex: 1;
      margin: 0 5px;
      line-height: 18px;
      color:$color-text-ll;
      font-size: $font-size-medium;
      &::placeholder{
        color:$color-text-ll
      }
    }

    .icon-dismiss{
      position: relative;
      @include extend-click;
      font-size: 16px;
      color: $color-text-d ;
      margin-right: 10px;
      font-weight:bold;
    }

  }

</style>